<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter"
                :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div class="search" v-show="pd.showSearch">
        <el-form :model="pd.queryParams" ref="queryFormRef" :inline="true" label-width="68px">
          <el-form-item label="线索名称" prop="name">
            <el-input v-model="pd.queryParams.name" placeholder="请输入线索名称" clearable style="width: 240px"
                      @keyup.enter="handleQuery"/>
          </el-form-item>
          <el-form-item label="客户来源" prop="source">
            <el-select v-model="pd.queryParams.source" placeholder="请选择客户来源" clearable>
              <el-option v-for="dict in hrp_lead_source" :key="dict.value" :label="dict.name" :value="dict.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="客户阶段" prop="stage">
            <el-select v-model="pd.queryParams.stage" placeholder="请选择客户阶段" clearable>
              <el-option v-for="dict in hrp_lead_source" :key="dict.value" :label="dict.name" :value="dict.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="失去原因" prop="lostReason">
            <el-select v-model="pd.queryParams.lostReason" placeholder="请选择失去原因" clearable>
              <el-option v-for="dict in hrp_lead_lost_reason" :key="dict.value" :label="dict.name" :value="dict.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="下次跟进" style="width: 308px">
            <el-date-picker
              v-model="dateRangeNextTime"
              value-format="YYYY-MM-DD HH:mm:ss"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['hrp:lead:add']">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" plain icon="Edit" :disabled="pd.single" @click="handleUpdate()"
                       v-hasPermi="['hrp:lead:edit']">修改
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain icon="Delete" :disabled="pd.multiple" @click="handleDelete()"
                       v-hasPermi="['hrp:lead:remove']">删除
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['hrp:lead:export']">导出
            </el-button>
          </el-col>
          <right-toolbar v-model:showSearch="pd.showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="pd.loading" :data="pd.leadList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="线索ID" align="center" prop="id" v-if="false"/>
        <el-table-column label="线索名称" align="center" prop="name">
          <template #default="scope">
            <el-link type="primary" @click="handleUpdate(scope.row)" v-hasPermi="['hrp:lead:edit']">
              {{ scope.row.name }}
            </el-link>
          </template>
        </el-table-column>
        <el-table-column label="客户" align="center" prop="partnerName"/>
        <el-table-column label="归属销售" align="center" prop="salesName"/>
        <el-table-column label="客户来源" align="center" prop="source">
          <template #default="scope">
            <dict-tag :options="hrp_lead_source" :value="scope.row.source"/>
          </template>
        </el-table-column>
        <el-table-column label="客户阶段" align="center" prop="stage">
          <template #default="scope">
            <dict-tag :options="hrp_lead_stage" :value="scope.row.stage"/>
          </template>
        </el-table-column>
        <el-table-column label="商机跟进" align="center" prop="remark">
          <template #default="scope">
            <el-link type="primary" @click="getCommentList(scope.row)" v-hasPermi="['hrp:lead:comment']">
              {{ scope.row.remark }}
            </el-link>
          </template>
        </el-table-column>
        <el-table-column label="失去原因" align="center" prop="lostReason">
          <template #default="scope">
            <dict-tag :options="hrp_lead_lost_reason" :value="scope.row.lostReason"/>
          </template>
        </el-table-column>
        <el-table-column label="下次跟进" align="center" prop="nextTime" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.nextTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column fixed="left" label="操作" align="center" class-name="small-padding fixed-width" width="165">
          <template #default="scope">
            <el-button link type="primary" icon="Finished" @click="handleTurnLead(scope.row)"
                       v-if="parseInt(scope.row.stage) < 6" v-hasPermi="['hrp:lead:edit']">转销售单
            </el-button>
            <el-button link type="primary" icon="Money" @click="quoteUpdate(scope.row)"
                       v-hasPermi="['hrp:lead:edit']">报价
            </el-button>
            <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
                       v-hasPermi="['hrp:lead:edit']">修改
            </el-button>
            <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row.id)"
                       v-if="scope.row.stage != '6'" v-hasPermi="['hrp:lead:remove']">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <Pagination
        v-show="pd.total>0"
        :total="pd.total"
        v-model:page="pd.queryParams.pageNum"
        v-model:limit="pd.queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>

    <!-- 添加或修改线索、商机-客户跟单对话框 -->
    <el-dialog :title="pd.dialog.title" v-model="pd.dialog.visible" width="1000px" append-to-body>
      <el-form ref="leadFormRef" :model="pd.form" :rules="pd.rules" label-width="80px">
        <el-row :gutter="20">
          <!-- First Column -->
          <el-col :span="8">
            <el-form-item label="线索名称" prop="name">
              <el-input v-model="pd.form.name" placeholder="请输入线索名称"/>
            </el-form-item>
            <el-form-item label="归属销售" prop="salesId">
              <UserSearch title="请选择归属销售" :data-text="pd.form.salesName" v-model="pd.form.salesId"
                          :params="{isSales :true}" @ok="userSearchSelected"/>
            </el-form-item>
            <el-form-item label="客户阶段" prop="stage">
              <el-select v-model="pd.form.stage" placeholder="请选择客户阶段">
                <el-option v-for="dict in hrp_lead_stage" :key="dict.value" :label="dict.name"
                           :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- Second Column -->
          <el-col :span="8">
            <el-form-item label="客户选择" prop="partnerId">
              <PartnerSearch :dataText="pd.form.partnerName" :params="{isCustomer:true}" @ok="searchCustomer1($event)"/>
            </el-form-item>
            <el-form-item label="失去原因" prop="lostReason">
              <el-select clearable v-model="pd.form.lostReason" placeholder="请选择失去原因">
                <el-option v-for="dict in hrp_lead_lost_reason" :key="dict.value" :label="dict.name"
                           :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- Third Column -->
          <el-col :span="8">
            <el-form-item label="客户来源" prop="source">
              <el-select v-model="pd.form.source" placeholder="请选择客户来源">
                <el-option v-for="dict in hrp_lead_source" :key="dict.value" :label="dict.name"
                           :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="下次跟进" prop="nextTime">
              <el-date-picker
                clearable
                v-model="pd.form.nextTime"
                type="datetime"
                value-format="YYYY-MM-DD HH:mm:ss"
                placeholder="请选择下次跟进"
              />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="跟进内容" prop="remark">
              <el-input v-model="pd.form.remark" type="textarea" placeholder="请输入内容"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="pd.buttonLoading" type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!--  报价  -->
    <el-dialog :title="pd.quoteDialog.title" v-model="pd.quoteDialog.visible" width="1000">
      <el-row class="mb8">
        <el-form :inline="true" disabled>
          <el-form-item label="线索名称">
            <el-input v-model="pd.form.name" style="width: 135px"/>
          </el-form-item>
          <el-form-item label="总金额">
            <el-input v-model="pd.money.totalMoney" style="width: 135px"/>
          </el-form-item>
          <el-form-item label="优惠金额">
            <el-input v-model="pd.money.discountMoney" style="width: 135px"/>
          </el-form-item>
          <el-form-item label="应收金额">
            <el-input v-model="pd.money.costMoney" style="width: 135px"/>
          </el-form-item>
        </el-form>
      </el-row>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="danger" @click="handleTurnLead(pd.form)">转销售单</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="success" @click="submitForm">保存</el-button>
        </el-col>
        <el-col :span="1.5">
          <ProductSearch :searchType="2" :params="{isSales:true}" @ok="lineAdd" title="产品查询" dataText="新增一行"/>
        </el-col>
        <el-col :span="1.5">
          <el-button :loading="pd.buttonLoading" icon="Refresh" @click="quoteUpdate">刷新</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button @click="cancel">关闭</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="pd.loading" :data="pd.form.quoteList">
        <el-table-column label="物品名称" align="center" prop="productName"/>
        <el-table-column label="单位" align="center" prop="measureUnit"/>
        <el-table-column label="采购价" align="center" prop="purchasePrice" width="80"/>
        <el-table-column label="售价" align="center" prop="price">
          <template #default="scope">
            <el-input @input="computeCostMoney(scope.row)" v-model="scope.row.price" placeholder="请输入采购价"/>
          </template>
        </el-table-column>
        <el-table-column label="数量" align="center" prop="quantity">
          <template #default="scope">
            <el-input @input="computeCostMoney(scope.row)" v-model="scope.row.quantity" placeholder="请输入数量"/>
          </template>
        </el-table-column>
        <el-table-column label="总金额" align="center" prop="totalMoney"/>
        <el-table-column label="优惠金额" align="center" prop="discountMoney">
          <template #default="scope">
            <el-input @input="computeCostMoney(scope.row)" v-model="scope.row.discountMoney" placeholder="请输入优惠金额"/>
          </template>
        </el-table-column>
        <el-table-column label="应收金额" align="center" prop="costMoney">
          <template #default="scope">
            <el-input @input="computeDiscountMoney(scope.row)" v-model="scope.row.costMoney" placeholder="应收金额"/>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="180">
          <template #default="scope">
            <el-button link type="primary" icon="Delete" @click="delLine(scope.row)" v-hasPermi="['hrp:example:del']">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <!-- 查看 -->
    <el-dialog :title="pd.inspectionDialog.title" v-model="pd.inspectionDialog.visible" width="1000">
      <el-descriptions>
        <el-descriptions-item label="客户">{{ pd.form.partnerName }}</el-descriptions-item>
        <el-descriptions-item label="线索名称">{{ pd.form.name }}</el-descriptions-item>
        <el-descriptions-item label="单据编号">{{ pd.form.id }}</el-descriptions-item>
        <el-descriptions-item label="总金额">{{ pd.money.totalMoney }}</el-descriptions-item>
        <el-descriptions-item label="优惠金额">{{ pd.money.discountMoney }}</el-descriptions-item>
        <el-descriptions-item label="应收金额">{{ pd.money.costMoney }}</el-descriptions-item>
      </el-descriptions>
      <el-table :data="pd.form.quoteList" stripe style="width: 100%">
        <el-table-column prop="productName" label="物品名称" width="120"/>
        <el-table-column prop="measureUnit" label="单位" width="120"/>
        <el-table-column prop="price" label="采购价" width="120"/>
        <el-table-column prop="quantity" label="数量" width="120"/>
        <el-table-column prop="totalMoney" label="总金额" width="120"/>
        <el-table-column prop="discountMoney" label="优惠金额" width="120"/>
        <el-table-column prop="costMoney" label="实际金额"/>
      </el-table>
      <pagination
        class="print-hidden"
        v-show="pd.quoteTotal>0"
        :total="pd.quoteTotal"
        v-model:page="pd.queryQuoteParams.pageNum"
        v-model:limit="pd.queryQuoteParams.pageSize"
        @pagination="getQuoteList"
      />
      <template #footer>
        <div class="dialog-footer">
          <el-button class="print-hidden" style="float: inherit" type="primary" @click="print">打印</el-button>
        </div>
      </template>
    </el-dialog>

    <!--  跟进详情-->
    <el-dialog :title="pd.comment.title" v-model="pd.comment.visible" width="520px" append-to-body>
      <el-timeline :reverse="true">
        <el-timeline-item v-for="(item, index) in pd.form.commentList" :key="index" :timestamp="item.createTime">
          <p style="display: flex">
            <strong>
              <dict-tag :options="hrp_lead_stage" :value="item.stage"/>
            </strong>
            <strong> : {{ item.nickName }} : </strong>
            {{ item.remark }}
          </p>
        </el-timeline-item>
      </el-timeline>
      <template #footer>
        <div slot="footer" class="dialog-footer">
          <el-button @click="pd.comment.visible = false">关闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Lead" lang="ts">
import {
  LeadVO, LeadQuoteVO, listLead, getLead, delLead, addLead, updateLead,
  turnLead, listLeadQuote, delLeadQuote, getCommentById, getQuoteListById
} from '@/views/hrp/lead/api';
import UserSearch from "@/views/system/user/search.vue";
import {UserVO} from "@/api/system/user/types";
import PartnerSearch from "@/views/hrp/partner/search.vue";
import {PartnerVO} from "@/views/hrp/partner/api";
import useUserStore from "@/store/modules/user";
import ProductSearch from "@/views/wms/product/search.vue";
import {ProductVO} from "@/views/wms/product/api";
import {addOrder, updateOrder} from "@/views/wms/order/api";

const {proxy} = getCurrentInstance() as ComponentInternalInstance;
const {
  hrp_lead_source,
  hrp_lead_lost_reason,
  hrp_lead_comment,
  hrp_lead_stage
} = toRefs<any>(proxy?.useDict('hrp_lead_source', 'hrp_lead_lost_reason', 'hrp_lead_comment', 'hrp_lead_stage'));
const dateRangeNextTime = ref<[DateModelType, DateModelType]>(['', '']);
const queryFormRef = ref<ElFormInstance>();
const leadFormRef = ref<ElFormInstance>();

const pd = reactive({
  createById: "",
  createByName: <string | undefined>(""),
  money: {
    totalMoney: 0,
    discountMoney: 0,
    costMoney: 0,
  },
  isBack: false,
  leadList: <LeadVO[]>([]),
  buttonLoading: false,
  loading: true,
  selectVO: <LeadVO[]>([]),
  showSearch: true,
  single: true,
  multiple: true,
  total: 0,
  quoteTotal: 0,
  commentTotal: 0,
  form: <LeadVO>{},
  queryParams: <LeadVO>{
    pageNum: 1,
    pageSize: 10,
  },
  dialog: <DialogOption>{
    visible: false,
    title: ''
  },
  queryQuoteParams: <LeadQuoteVO>{
    pageNum: 1,
    pageSize: 10,
  },
  rules: <ElFormRules>{
    name: [
      {required: true, message: "线索名称不能为空", trigger: "blur"}
    ],
    partnerId: [
      {required: true, message: "客户id不能为空", trigger: "change"}
    ],
    salesId: [
      {required: true, message: "归属销售不能为空", trigger: "change"}
    ],
    source: [
      {required: true, message: "客户来源不能为空", trigger: "change"}
    ],
    stage: [
      {required: true, message: "客户阶段不能为空", trigger: "change"}
    ],
    nextTime: [
      {required: true, message: "下次跟进时间不能为空", trigger: "blur"}
    ],
    remark: [
      {required: true, message: "商机跟进信息不能为空", trigger: "blur"}
    ],
  },
  inspectionDialog: <DialogOption>{
    visible: false,
    title: '线索、商机-客户跟单'
  },
  quoteDialog: <DialogOption>{
    visible: false,
    title: '报价'
  },
  comment: <DialogOption>{
    visible: false,
    title: '商机跟进记录详情'
  },
});

/** 查询线索、商机-客户跟单列表 */
async function getList() {
  pd.loading = true;
  pd.queryParams.params = {};
  proxy?.addDateRange(pd.queryParams, dateRangeNextTime.value, 'NextTime');
  const res = await listLead(pd.queryParams);
  pd.leadList = res.rows;
  pd.total = res.total;
  pd.loading = false;
}

function print() {
  window.print();
}

/** 取消按钮 */
function cancel() {
  reset();
  pd.quoteDialog.visible = false;
  pd.dialog.visible = false;
}

/** 表单重置 */
function reset() {
  pd.form = {};
  pd.form.quoteList = [];
  pd.money = {
    totalMoney: 0,
    discountMoney: 0,
    costMoney: 0,
  }
  leadFormRef.value?.resetFields();
  pd.form.createBy = parseInt(pd.createById);
  pd.form.salesId = pd.createById;
}

/** 搜索按钮操作 */
function handleQuery() {
  pd.queryParams.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  dateRangeNextTime.value = ['', ''];
  queryFormRef.value?.resetFields();
  handleQuery();
}

/** 多选框选中数据 */
function handleSelectionChange(selection: LeadVO[]) {
  pd.selectVO = selection;
  pd.single = selection.length != 1;
  pd.multiple = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  pd.form.stage = "1";
  pd.form.partnerName = "";
  pd.form.salesName = pd.createByName;
  pd.dialog.title = "添加线索、商机-客户跟单";
  pd.dialog.visible = true;
}

function searchCustomer1(pVo: PartnerVO[]) {
  pVo.forEach((v, i, a) => {
    pd.form.partnerId = v.id;
    pd.form.partnerName = v.name;
    return;
  });
}

function userSearchSelected(val: UserVO[]) {
  val.forEach(v => {
    pd.form.salesId = v.userId;
    pd.form.salesName = v.nickName;
  })
  return;
}

/** 修改按钮操作 */
async function handleUpdate(row?: LeadVO) {
  reset();
  if (row?.id){
    Object.assign(pd.form, row);
  }else {
    Object.assign(pd.form, pd.selectVO[0]);
  }
  pd.form.remark = null;
  pd.form.updateBy = parseInt(pd.createById);
  pd.dialog.visible = true;
  pd.dialog.title = "修改线索、商机-客户跟单";
}

//报价按钮 查询订单列表
async function quoteUpdate(row?: LeadVO) {
  if (row?.id) {
    console.log(row)
    reset();
    Object.assign(pd.form, row);
  }
  pd.buttonLoading = true;
  if (pd.form?.id){
    await getQuoteListById(pd.form?.id).then(value => {
      pd.form.quoteList = value.rows
      pd.loading = false;
      computedTotalMoney()
    })
  }
  if (row?.stage != "6") {
    pd.quoteDialog.visible = true;
  } else {
    pd.inspectionDialog.visible = true;
  }
  pd.buttonLoading = false;
}

//执行
async function handleTurnLead(row: LeadVO) {
  await proxy?.$modal.confirm("确认完成跟单，并转到销售单据：" + row.name + " 吗?");
  row.stage = "6";
  await turnLead(row).then(() => {
    proxy?.$modal.msgSuccess("转销售单成功！！！");
    getList();
  });
}

// 计算金额
function computeCostMoney(vo: LeadQuoteVO) {
  if (vo.quantity != undefined) {
    vo.totalMoney = vo.quantity * vo.price!;
    vo.costMoney = vo.totalMoney - vo.discountMoney!;
    vo.discountMoney = vo.totalMoney - vo.costMoney!;
    computedTotalMoney()
  }
}

// 计算金额
function computeDiscountMoney(vo: LeadQuoteVO) {
  if (vo.quantity != undefined) {
    vo.totalMoney = vo.quantity * vo.price!;
    vo.discountMoney = vo.totalMoney - vo.costMoney!;
    vo.costMoney = vo.totalMoney - vo.discountMoney!;
    computedTotalMoney()
  }
}

function computedTotalMoney() {
  pd.money = {
    totalMoney: 0,
    discountMoney: 0,
    costMoney: 0,
  }
  pd.form.quoteList?.forEach(value => {
    if (value.totalMoney != undefined && value.totalMoney > 0) pd.money.totalMoney += value.totalMoney;
    if (value.discountMoney != undefined && value.discountMoney > 0) pd.money.discountMoney += value.discountMoney;
    if (value.costMoney != undefined && value.costMoney > 0) pd.money.costMoney += value.costMoney;
  })
}

/** 查询订单列表 */
async function getQuoteList() {
  pd.buttonLoading = true;
  pd.queryQuoteParams.id = pd.form.id;
  await listLeadQuote(pd.queryQuoteParams).then(res => {
    pd.form.quoteList = res.rows;
    pd.quoteTotal = res.total;
    pd.buttonLoading = false;
  });
}

/** 提交按钮 */
async function submitForm() {
  leadFormRef.value?.validate(async (valid: boolean) => {
    if (!valid) {
      return ;
    }
    pd.buttonLoading = true;
    if (pd.form.id) {
      await updateLead(pd.form).finally(() => {
        pd.buttonLoading = false;
      });
    } else {
      await addLead(pd.form).finally(() => {
        pd.buttonLoading = false
      });
    }
    pd.dialog.visible = false;
    pd.quoteDialog.visible = false;
    await getList();
  })
}

//转销售单
// async function turn() {
//   pd.buttonLoading = true;
//   await turnOrder(pd.form).then(res => {
//     res.code == 200 ? proxy?.$modal.msgSuccess(res.msg) : proxy?.$modal.msgWarning(res.msg)
//   }).finally(() => {
//     pd.buttonLoading = false;
//     pd.dialog.visible = false;
//     pd.quoteDialog.visible = false;
//   })
// }

//新增一行
function lineAdd(vo: ProductVO[]) {
  vo.forEach((v) => {
    let quote: LeadQuoteVO = {
      productId: v.id as number,
      productName: v.name,
      price: v.price,
      measureUnit: v.measureUnit,
      quantity: 1,
      totalMoney: v.price!,
      costMoney: v.price!,
      discountMoney: 0,
      purchasePrice: v.purchasePrice,
      isStock: v.isStock
    };
    pd.form.quoteList!.push(quote);
  });
  computedTotalMoney();
}

async function getCommentList(vo: LeadVO) {
  if (vo.id != undefined) {
    await getCommentById(vo.id).then(value => {
      pd.form.commentList = value.rows;
    })
  }
  pd.comment.visible = true;
}

/** 删除按钮操作 */
async function handleDelete(id?: string | number) {
  const _ids = id ? id : pd.selectVO.map(v => v.id);
  await proxy?.$modal.confirm('是否确认删除线索、商机-客户跟单编号为"' + _ids + '"的数据项？').finally(() => pd.loading = false);
  await delLead(_ids);
  proxy?.$modal.msgSuccess("删除成功");
  pd.dialog.visible = false;
  await getList();
}

/** 删除子表操作 */
async function delLine(row: LeadQuoteVO) {
  if (row.quoteId === undefined || row.quoteId == null) {
    const index = pd.form.quoteList!.indexOf(row);
    pd.form.quoteList?.splice(index, 1);
  } else {
    proxy?.$modal.confirm('是否确认删除 子单号为:"' + row.quoteId + '"的数据项？').then(function () {
      return delLeadQuote(row.quoteId!);
    }).then(() => {
      const index = pd.form.quoteList!.indexOf(row);
      pd.form.quoteList?.splice(index, 1);
      proxy.$modal.msgSuccess("删除成功");
    })
  }
  computedTotalMoney();
}

/** 导出按钮操作 */
function handleExport() {
  proxy?.download('hrp/lead/export', {
    ...pd.queryParams
  }, `lead_${new Date().getTime()}.xlsx`)
}

onMounted(() => {
  pd.createById = JSON.parse(JSON.stringify(useUserStore().getUserId().value));
  pd.createByName = JSON.parse(JSON.stringify(useUserStore().getNickName().value));
  getList();
});
</script>
